/*
 * Sycloud.com Inc.
 * Copyright (c) 2005-2066 All Rights Reserved.
 */
package com.insigma.business.qrcode.common.converter;


import com.insigma.business.common.utils.CurrentUserUtil;
import com.insigma.business.qrcode.common.converter.AbstractConverter;
import com.insigma.business.qrcode.welfare.dto.CareWelfareServiceOrganizationDTO;
import com.insigma.business.qrcode.welfare.entity.CareWelfareServiceOrganizationDO;
import com.insigma.business.qrcode.welfare.request.CareWelfareServiceOrganizationInsertRequest;
import com.insigma.business.qrcode.welfare.request.CareWelfareServiceOrganizationSearchRequest;
import com.insigma.business.qrcode.welfare.dto.CareWelfareServiceOrganizationBSearcher;
import com.insigma.business.qrcode.welfare.request.CareWelfareServiceOrganizationUpdateRequest;
import org.springframework.beans.BeanUtils;

import java.util.List;


/**
 * @author juffett
 * @version $Id: CareWelfareServiceOrganizationProviderConverter.java, v 1.0.0 2021-9-9 14:45:13 juffett Exp $
 */
public class CareWelfareServiceOrganizationProviderConverter extends AbstractConverter<CareWelfareServiceOrganizationDTO, CareWelfareServiceOrganizationDO> {

    private final static CareWelfareServiceOrganizationProviderConverter careWelfareServiceOrganizationConverter = new CareWelfareServiceOrganizationProviderConverter();

    private CareWelfareServiceOrganizationProviderConverter(){}

    /**
     * 远端请求过来后，将远端的查询请求转化成本地搜索器
     *
     * @param request
     * @return
     */
    public static CareWelfareServiceOrganizationBSearcher convertRequestSO2Searcher(final CareWelfareServiceOrganizationSearchRequest request){
        final CareWelfareServiceOrganizationBSearcher careWelfareServiceOrganizationBSearcher = new CareWelfareServiceOrganizationBSearcher(request.getPageNo(),
        request.getPageSize(),request.getSortKeyValueJoint());
        BeanUtils.copyProperties(request,careWelfareServiceOrganizationBSearcher);
        return careWelfareServiceOrganizationBSearcher;
    }

    /**
     * 远端请求过来后，将远端的更新请求转化为本地领域对象
     *
     * @param careWelfareServiceOrganizationUpdateRequest
     * @return
     */
    public static CareWelfareServiceOrganizationDO convertRequestIO2DO(final CareWelfareServiceOrganizationInsertRequest careWelfareServiceOrganizationInsertRequest) {
        final CareWelfareServiceOrganizationDO careWelfareServiceOrganizationDO = new CareWelfareServiceOrganizationDO();
        BeanUtils.copyProperties(careWelfareServiceOrganizationInsertRequest,careWelfareServiceOrganizationDO);
        return careWelfareServiceOrganizationDO;
    }

    public static CareWelfareServiceOrganizationDO convertRequestUO2DO(final CareWelfareServiceOrganizationUpdateRequest careWelfareServiceOrganizationUpdateRequest) {
        final CareWelfareServiceOrganizationDO careWelfareServiceOrganizationDO = new CareWelfareServiceOrganizationDO();
        BeanUtils.copyProperties(careWelfareServiceOrganizationUpdateRequest,careWelfareServiceOrganizationDO);
        //careWelfareServiceOrganizationDO.setId(careWelfareServiceOrganizationUpdateRequest.getId());
        return careWelfareServiceOrganizationDO;
    }

    /**
     * 远端请求过来后，将远端的插入请求转化为本地领域对象
     *
     * @param careWelfareServiceOrganizationInsertRequest
     * @return
     */


    /**
     * 响应远端时，将领域对象列表转化为本地对象列表返回给远端
     *
     * @param careWelfareServiceOrganizationDOList
     * @return
     */
    public static List<CareWelfareServiceOrganizationDTO> convertResponseDOList2DTOList(final List<CareWelfareServiceOrganizationDO> careWelfareServiceOrganizationDOList){
        return careWelfareServiceOrganizationConverter.convertGenericResponseDOList2DTOList(careWelfareServiceOrganizationDOList);
    }

    /**
     * 响应远端时，将领域对象转化为本地对象返回给远端
     *
     * @param careWelfareServiceOrganizationDO
     * @return
     */
    public static CareWelfareServiceOrganizationDTO convertResponseDO2DTO(final CareWelfareServiceOrganizationDO careWelfareServiceOrganizationDO){
        return careWelfareServiceOrganizationConverter.convertGenericResponseDO2DTO(careWelfareServiceOrganizationDO);
    }

    /**
     * @see AbstractConverter#doConvertResponseDO2DTO(BaseDO)
     */
    @Override
    protected CareWelfareServiceOrganizationDTO doConvertResponseDO2DTO(CareWelfareServiceOrganizationDO careWelfareServiceOrganizationDO) {
        final CareWelfareServiceOrganizationDTO careWelfareServiceOrganizationDTO = new CareWelfareServiceOrganizationDTO();
        try {
            BeanUtils.copyProperties(careWelfareServiceOrganizationDO, careWelfareServiceOrganizationDTO);
        }catch(RuntimeException be){
            //此处表示DO和RO不一致，此时我们不能够使用BeanUtils拷贝方式，而需要一个个赋值。
            return null;
        }
        return careWelfareServiceOrganizationDTO;
    }

}
